package com.example.goods.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;

import java.util.Map;


@Mapper
public interface ArticleMapper {

    @Insert("insert into article(id,name,summary,price,number,create_time) value " +
            "(#{id},#{name},#{summary},#{price},#{number},#{create_time})")
    int addArticle(@Param("id") String id, @Param("name") String name, @Param("summary") String summary, @Param("price") String price,
                   @Param("number") int number, @Param("create_time") String createTime);

    @Select("select id,name,summary,price,number,create_time from article where status =1")
    IPage<Map<String, Object>> selectArticleByShow(IPage<Map<String, Object>> page);


    @Select("select id,name,summary,price,number,create_time,status from article where id = #{id}")
    Map<String, Object> selectArticle(String id);

    @Select("select id,name,summary,price,number,create_time,status from article where id = #{id} for update")
//    @Select("select id,name,summary,price,number,create_time,status from article where id = #{id}")
    Map<String, Object> selectArticleForUpdate(String id);

    @Update("update article set number = number-1 where id = #{order_id}")
    int updateOrderNumber(@Param("order_id") String orderId);
}
